package zuochengyun.node;

import java.util.Random;

public class NodeSignole {
    public static class Node {
        public int value;
        public Node next;

        public Node(int value) {
            this.value = value;
        }
    }

    public static class DoubleNode {
        public int value;
        public DoubleNode next;
        public DoubleNode last;

        public DoubleNode(int value) {
            this.value = value;
        }
    }

    public static void main(String[] args) {

    }

    public static Node generateRandomLinkedList(int lenMaxValue, int dataManValue) {
        int len = (int) Math.random() * (lenMaxValue + 1);
        if (len == 0) {
            return null;
        }
        len--;
        Node head = new Node((int) Math.random() * (dataManValue + 1));
        Node pre = head;
        while (len > 0) {
            Node data = new Node((int) Math.random() * (dataManValue + 1));
            pre.next = data;
            pre = data;
            len--;
        }
        return head;
    }

    public static Node reverseLinkedList(Node node) {
        Node pre = null;
        Node next = null;
        while (node != null) {
            next = node.next;
            node.next = pre;
            pre = node;
            node = next;
        }
        return pre;
    }

    public static DoubleNode reverseDoubleNode(DoubleNode doubleNode){
        DoubleNode pre = null;
        DoubleNode next = null;
        while (doubleNode!=null){
            next = doubleNode.next;
            doubleNode.next = pre;
            doubleNode.last = next;
            pre = doubleNode;
            doubleNode = next;
        }

        return  pre;
    }
}
